<?php
/**
 * 阿里云相关服务
 * zhouliang
 * 2020.09.10
 */

namespace App\Services\Tools;

use App\Response\Response;
use Illuminate\Http\Request;
use App\Exceptions\BasicException;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
use Carbon\Carbon;

class CommonService {

    //获取符合体条件的游戏列表
    public static  function  gameList($user_id=0){
        $rank_id = app('repo_user')->getUserRank($user_id);
        if ($rank_id <=0){
            $rank_id =0;
        }
        $where[]= ['start_time','<',time()];
        $where[]= ['end_time','>',time()];
        $where[]= ['user_grade','<=',$rank_id];
        $where[] =['status',1];
        $data =app('repo_game_entrance')->list($where);
        $new_data =[];
        if ($data){
            $hour = date('H',time());
            $game_ids = array_column($data,'time_slot','game_id');
            foreach ($game_ids as  $key=>$game_id){
                $arr_time_slot =json_decode($game_id,true);
                foreach ($arr_time_slot as $k=>$value){
                    if ($value[0] <= $hour &&  $value[1] >= $hour){
                        $new_data[] =$key;
                    }
                }
            }
        }
        return $new_data;
    }


    //获得今天起止时间
    public static function getTodayTime()
    {
        $res = array();
        $res['start_at'] = Carbon::now()->startOfDay()->timestamp;
        $res['end_at'] = Carbon::now()->endOfDay()->timestamp;
        return $res;
    }











}

